package com.norma.netty.study.netty.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author zhangchaofeng
 * @date 2020/10/5
 * @description
 */
public class NettyMessageEncoder extends MessageToByteEncoder<NettyMessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, NettyMessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println("------> NettyMessageEncoder()");
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}
